1
2
3
4
5
6
7
8 package io;
9
10 import java.io.*;
11
12 /***
13 *
14 * @author Barrie Treloar
15 */
16 public class IOUtilities
17 {
18 private IOUtilities()
19 {
20 }
21
22 public static byte[] readAllBytes( InputStream in ) throws IOException
23 {
24 byte[] result = new byte[ 0 ];
25 BufferedInputStream bin = new BufferedInputStream( in );
26 byte[] buffer = new byte[ 256 ];
27 int bytesRead = 0;
28 while ( ( bytesRead = bin.read( buffer, 0, buffer.length ) ) != -1 )
29 {
30 int newLength = result.length + bytesRead;
31 byte[] tmpArray = new byte[ newLength ];
32 System.arraycopy( result, 0, tmpArray, 0, result.length );
33 System.arraycopy( buffer, 0, tmpArray, result.length, bytesRead );
34 result = tmpArray;
35 }
36 return result;
37 }
38 }
39